package com.blb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.entity.Logistics;
import com.blb.entity.ProductionLine;
import com.blb.entity.User;
import com.blb.mapper.LogisticsMapper;
import com.blb.service.ILogisticsService;
import com.blb.utils.UUIDUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *物流管理的物流公司信息管理
 * @author wss
 * @since 2020-05-22
 */
@Controller
@RequestMapping("/logistics")
public class LogisticsController {

    @Autowired
    ILogisticsService iLogisticsService;
    @Resource
    LogisticsMapper logisticsMapper;

    @RequiresPermissions("logisticsinfo")
    @RequestMapping("/info")
    @ResponseBody
    public Page<Logistics> list(int page, int limit){
        return iLogisticsService.page(new Page<Logistics>(page,limit),new QueryWrapper<Logistics>());
    }
    @RequiresPermissions("logisticsinfo")
    @RequestMapping("/name")
    @ResponseBody
    public Page<Logistics> getname(int page, int limit,String name){
        return logisticsMapper.selectPage(new Page<Logistics>(page,limit),new QueryWrapper<Logistics>());
    }
    @RequiresPermissions("logisticsinfo:add")
    @RequestMapping("/info_add")
    @ResponseBody
    public String save(Logistics logistics){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        logistics.setId(UUIDUtils.id());
        logistics.setCompanyId("1");
        logistics.setCreateTime(new Date());
        iLogisticsService.save(logistics);
        return "1";
    }
    @RequiresPermissions("logisticsinfo:update")
    @RequestMapping("/info_upp")
    @ResponseBody
    public String update(Logistics logistics){
        iLogisticsService.update(logistics,new UpdateWrapper<Logistics>().eq("id",logistics.getId()));
        return "1";
    }
    @RequiresPermissions("logisticsinfo:deleted")
    @RequestMapping("/info_del")
    @ResponseBody
    public String delete(String id){
        iLogisticsService.removeById(id);
        return "1";
    }
}

